<?php
//***************  add by code   ******************
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of article
 *
 * @author Administrator
 */
class company_news extends CI_Controller {

    private $page_size=10;
    private $parentid;

    public function __construct() {
        parent::__construct();
        $this->url = $this->uri->segments;
        $this->CI = & get_instance();
    }

    public function index() {
        $this->CI->load->library('a_article');

        $g_nav_list = $this->CI->load->get_var('g_nav_list');//获取导航
        $url_info = $this->url;
        $action = $url_info[2];
        $data['action_info'] = $this->m_public->getRowInfo('class',array('classlinkname'=>$action,'configid'=>CONFIG_ID));
        $data['brother_info'] = $this->m_public->getAllInfo('class',array('parentid'=>$data['action_info']['parentid']));
        $data['parent_info'] = $this->m_public->getRowInfo('class',array('classid'=>$data['action_info']['parentid']));

        $page = isset($_GET['page'])?$_GET['page']:1;//当前页
        $data['article_list'] = $this->CI->a_article->get_article_list_page(CONFIG_ID,$data['action_info']['classid'],'',$page,$this->page_size);
        $this->load->helper('array_func_helper');
        $arr = array (
            'page' => $page,//当前页
            'page_size' => $this->page_size,     //分页总大小
            'total' => $data['article_list']['page']['cnt']//总记录数
        );
        $start_page = ($page-1)*$this->page_size;
        $data['pagination'] = new pagination($arr);

        /*SEO部分*/
        if(isset($data['action_info']['seotitle']) && !empty($data['action_info']['seotitle']))
            $data['g_site']['websitename'] = $data['action_info']['seotitle'];
        if(isset($data['action_info']['keywords']) && !empty($data['action_info']['keywords']))
            $data['g_site']['websitekeywords'] = $data['action_info']['keywords'];
        if(isset($data['action_info']['description']) && !empty($data['action_info']['description']))
            $data['g_site']['websitedescription'] = $data['action_info']['description'];

        /*左侧部分，联系我们*/
        $contact_config = $this->m_public->getRowInfo('config',array('configid'=>CONFIG_ID),'contact_config');
        $data['contact'] = json_decode($contact_config['contact_config'],true);

        /*头部,底部数据*/
        $config = $this->m_public->getRowInfo('config',array('configid'=>CONFIG_ID),'copyright,banquan,contact_config,footerinfo');
        $config['contact_config'] = json_decode($config['contact_config'],true);
        $data['config'] = $config;
        $footer_condition = array(
            'from' => 'link',
            'where' => array('isclose'=>0,'typeid'=>1,'configid'=>CONFIG_ID),
            'order' => 'listid'
        );
        $data['footer_info'] = $this->m_public->get_list($footer_condition);

        /*导航选中状态*/
        $this->get_parent_id($data['action_info']['classid']);
        $data['parentid'] = $this->parentid;

        $this->load->view('../en/template_article_list',$data);
    }

    public function get_parent_id($id){
            if($id){
                $info = $this->m_public->getRowInfo('class',array('classid'=>$id));
                $parent_info = $this->m_public->getRowInfo('class',array('classid'=>$info['parentid']));
                if(!empty($parent_info)){
                    if($parent_info['parentid'] == 0){
                        $this->parentid = $parent_info['classid'];
                    }else{
                        $this->get_parent_id($parent_info['classid']);
                    }
                }
            }
        }

}
